package servlet.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.User;

/**
 * Servlet Filter implementation class BuyMulFilter
 */
public class BuyMulFilter implements Filter {

    /**
     * Default constructor. 
     */
    public BuyMulFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		// place your code here
		HttpServletRequest hsRequest=(HttpServletRequest)request;
		HttpServletResponse hsResponse=(HttpServletResponse)response;
			
		String pathString=hsRequest.getServletPath();
		int num=pathString.split("/").length-3;
		String path="";
		for(int i=0;i<num;i++)
			path=path+"../";
		path=path+"buy";
		System.out.println(path);
		hsRequest.getRequestDispatcher(path).forward(hsRequest, hsResponse);
		// pass the request along the filter chain
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
